package cn.unknowpupil.init.domain.dto;

/**
 * Created at 2020/11/25 by w10g <br>
 * Initialize TreeSelect ... <br>
 *
 * @author unknowpupil
 * @since 0.0.1
 */

import cn.unknowpupil.init.domain.system.SysPermission;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created at 2020/10/30 by w10g <br>
 * Initialize TreeSelect ... <br>
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 8327007981819985609L;
    /** 节点ID */
    @ApiModelProperty(value = "节点ID")
    private Long id;

    /** 节点名称 */
    @ApiModelProperty(value = "节点名称")
    private String label;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @ApiModelProperty(value = "子节点")
    private List<TreeSelect> children;



    public TreeSelect(SysPermission permission)
    {
        this.id = permission.getId();
        this.label = permission.getName();
        this.children = permission.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }
}

